const router = require('koa-router')()
const fs = require('fs')

router.post('/upload', async (ctx, next) => {
    // 上传单个文件
    const file = ctx.request.files.file; // 获取上传文件
    // 创建可读流
    const reader = fs.createReadStream(file.path);
    let filePath = `${__dirname.replace('\\routes','')}\\public\\temporary\\${file.name}`;//${Date.now().toString()}.
    // 创建可写流
    const upStream = fs.createWriteStream(filePath);
    // 可读流通过管道写入可写流
    reader.pipe(upStream);
    return ctx.body = "上传成功！";
});

module.exports = router
